package com.slixils.demo.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.slixils.demo.vo.ResultMessage;

/**
 * @Author: JinChongLi
 * @Description:
 * @Date: Created in 16:33 2021/11/6
 * @Modified By:
 */
public class MessageUtils {
    public static String getMessage(boolean isSystemMessage,String fromName,Object message){
        try {
            ResultMessage resultMessage = new ResultMessage();
            resultMessage.setMessage(isSystemMessage);
            resultMessage.setMessage(message);
            if (fromName!=null){
                resultMessage.setFromName(fromName);
                ObjectMapper objectMapper = new ObjectMapper();
                return objectMapper.writeValueAsString(resultMessage);
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
